package leetcode;

public class TranslateNum {
    public static void main(String[] args) {
        TranslateNum translateNum = new TranslateNum();
        System.out.println(translateNum.translateNum(506));
    }

    public int translateNum(int num) {
        if (num <= 9) {
            return 1;
        }
        String str = String.valueOf(num);
        int n = str.length();
        int[] dp = new int[n];
        char[] num_char = str.toCharArray();
        dp[0] = 1;
        if (((num_char[0] - '0') * 10) + num_char[1] - '0' >= 26) {
            dp[1] = dp[0];
        } else {
            dp[1] = 2;
        }
        for (int i = 2; i < num_char.length; i++) {
            if (((num_char[i - 1] - '0') * 10) + num_char[i] - '0' >= 26 || num_char[i - 1] == '0') {
                dp[i] = dp[i - 1];
            } else {
                dp[i] = dp[i - 1] + dp[i - 2];
            }
        }
        return dp[n - 1];
    }
}
